// 递归实现
function FibonacciRecursive(n: number): number {
    if (n <= 1) {
        return n;
    } else {
        return FibonacciRecursive(n - 1) + FibonacciRecursive(n - 2);
    }
}

// 迭代实现
function FibonacciIterative(n: number): number {
    if (n <= 1) {
        return n;
    }

    let a: number = 0, b: number = 1;
    for (let i: number = 2; i <= n; i++) {
        const c: number = a + b;
        a = b;
        b = c;
    }
    return b;
}

function main(): void {
    const n: number = 30;
    console.log(`TypeScript Fibonacci(${n})`);

    // 测试递归实现
    const startRecursive: number = performance.now();
    const fibRecursive: number = FibonacciRecursive(n);
    const endRecursive: number = performance.now();
    console.log(`Recursive result: ${fibRecursive}`);
    console.log(`Recursive Execution time: ${(endRecursive - startRecursive) / 1000} seconds`);

    // 测试迭代实现
    const startIterative: number = performance.now();
    const fibIterative: number = FibonacciIterative(n);
    const endIterative: number = performance.now();
    console.log(`Iterative result: ${fibIterative}`);
    console.log(`Iterative Execution time: ${(endIterative - startIterative) / 1000} seconds`);
}

main();